package day03;

import java.io.*;

/**
 * 将当前目录下的所有obj文件获取到，并进行
 * 反序列化后输出每个用户的信息(直接输出反序列化后的User对象即可)
 * @author Xiloer
 */
public class Test02 {
    /*public static void main(String[] args) throws IOException, ClassNotFoundException {
        File dir = new File("./File");
        if (dir.isDirectory()) { //如果dir是目录
            File[] subs = dir.listFiles(f -> f.getName().endsWith(".obj")); //将所有后缀为obj的文件放在subs中
            for (File f : subs) {
                FileInputStream fis = new FileInputStream(f);  //文件输入流
                ObjectInputStream ois = new ObjectInputStream(fis);//对象输入流
                User u = (User) ois.readObject();
                System.out.println(u);
                ois.close();
            }
        }*/
        public static void main(String[] args) throws IOException, ClassNotFoundException {
            File dir = new File("./File");
            if (dir.isDirectory()) {
                File[] subs = dir.listFiles(f -> f.getName().endsWith(".obj"));
                for (File f : subs) {
                    FileInputStream fis = new FileInputStream(f);
                    ObjectInputStream ois = new ObjectInputStream(fis);
                    User u = (User) ois.readObject();
                    System.out.println(u);
                    ois.close();
                }
            }
        }
    }
//}


